﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ExpenseSystem.Common;
using ExpenseSystem.Common.BaseModel;
using ExpenseSystem.DataUpdater;
using ExpenseSystem.Fether;
using ExpenseSystem.Model;
using ExpenseSystem.Core.DataAddOn;
using System.Web;

namespace ExpenseSystem.Core.OrderModules
{
    public abstract class OrderManager : INormalManager<OrderModel>,IApproveable<OrderModel>
    {
        protected OrderManager()
        {
            profile = Authority.Authority.GetUserProfile();
        }
        protected string tran = HttpContext.Current.Items[Definition.SESSION_TRAN_STR].ToString();


        protected UserProfile profile;
        public static OrderManager CreateInstance()
        {
            return new OrderStateUpdateManager( new OrderUpdateCustomerManager( new OrderBaseManager()));
        }
        protected NormalDataUpdater<OrderModel> OrderUpdater = new OrderUpdaterRegister().GetOrderUpdater();

        public abstract bool Delete( OrderModel Order, out string message);
        public abstract bool DeleteById( long[] OrderId, out string message);
        public abstract bool Save(OrderModel Order,  out string message, params IAddable<OrderModel>[] addables);

        public virtual  bool Approved(long id, out string message)
        {
            ApprovedHelper<OrderModel> approvedHelper = new ApprovedHelper<OrderModel>(new OrderFetcher(),this);
            return approvedHelper.Approved(id,out message);
        }

        public virtual  bool Reject(long id, out string message)
        {
            ApprovedHelper<OrderModel> approvedHelper = new ApprovedHelper<OrderModel>(new OrderFetcher(), this);
            return approvedHelper.Reject(id, out message);
        }

        public virtual  bool Comfirm(long id, out string message)
        {
            ApprovedHelper<OrderModel> approvedHelper = new ApprovedHelper<OrderModel>(new OrderFetcher(), this);
            return approvedHelper.Comfirm(id, out message);
        }

        public virtual bool Submit(long modelid, out string message)
        {
            ApprovedHelper<OrderModel> approvedHelper = new ApprovedHelper<OrderModel>(new OrderFetcher(), this);
            return approvedHelper.Submit(modelid, out message);
        }

        public virtual bool Recall(long modelid, out string message)
        {
            ApprovedHelper<OrderModel> approvedHelper = new ApprovedHelper<OrderModel>(new OrderFetcher(), this);
            return approvedHelper.Recall(modelid, out message);
        }
        public virtual bool Revert(long modelid, out string message)
        {
            ApprovedHelper<OrderModel> approvedHelper = new ApprovedHelper<OrderModel>(new OrderFetcher(), this);
            return approvedHelper.Revert(modelid, out message);
        }
    }
}
